<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button>replace 不可以后退</button>
    <button>assign 可以后退</button>
    <button>reload 刷新</button>
    <script>
        // 返回整个url
        console.log(location.href,'href返回整个主机名');
        // 返回主机
        console.log(location.host,'host主机');
        // 返回url端口号
        console.log(location.port,'port返回端口号');
        // 返回url路径
        console.log(location.pathname);
        // 返回参数
        console.log(location.search);
        // 返回hash值
        console.log(location.hash);

        var btns = document.querySelectorAll('button')
        btns[0].onclick = ()=>location.replace('http://www.baidu.com')
        btns[1].onclick = ()=>location.assign('http://www.baidu.com')
        btns[2].onclick = ()=>location.reload()
        
        
        
    </script>
</body>
</html>